package com.redisson;

import org.redisson.Redisson;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.redisson.client.RedisClient;
import org.redisson.config.Config;

public class RedissonBloomFilter {

    public static void main(String[] args) {

        Config config=new Config();
        config.useSingleServer().setAddress("redis://192.168.0.105:6379");
        //构造Redisson
        RedissonClient redisson = Redisson.create(config);
        RBloomFilter<String> bloomFilter=redisson.getBloomFilter("nameList");
        //初始化布隆过滤器：预计元素为100000000L,误差率为3%,根据这两个参数会计算出底层的bit数组大小
        bloomFilter.tryInit(100000L,0.03);

        //将test插入到布隆过滤器中
        bloomFilter.add("test-hjp");
        bloomFilter.add("test-java");

        //判断下面号码是否在布隆过滤器中
        System.out.println(bloomFilter.contains("test"));
        System.out.println(bloomFilter.contains("test-hjp"));
        System.out.println(bloomFilter.contains("test-java"));


    }
}
